package com.vanzo.some.appinfo;

import java.text.Collator;
import java.util.Comparator;

/**
 * Created by tisen on 2017/10/26.
 */

public class AppComparator implements Comparator<AppInfo> {
    private Collator collator = Collator.getInstance();

    @Override
    public int compare(AppInfo o1, AppInfo o2) {
        if (Cn2Spell.isChinese(o1.getLabel()) && Cn2Spell.isChinese(o2.getLabel())) {
            return collator.getCollationKey(Cn2Spell.converterToSpell(o1.getLabel())).compareTo(collator.getCollationKey(Cn2Spell.converterToSpell(o2.getLabel())));
        }
        if (Cn2Spell.isChinese(o1.getLabel()) && !Cn2Spell.isChinese(o2.getLabel())) {
            return -1;
        }
        if (!Cn2Spell.isChinese(o1.getLabel()) && Cn2Spell.isChinese(o2.getLabel())) {
            return 1;
        }
        if (!Cn2Spell.isChinese(o1.getLabel()) && !Cn2Spell.isChinese(o2.getLabel())) {
            return collator.getCollationKey(o1.getLabel()).compareTo(collator.getCollationKey(o2.getLabel()));
        }
        return 0;
    }


}
